package com.mj.haier.calc.repository;

import com.mj.haier.calc.domain.AzEorderTitle;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;

import java.time.Instant;
import java.util.*;

import javax.transaction.Transactional;



/**
 * Spring Data  repository for the AzEorderTitle entity.
 */
@SuppressWarnings("unused")
@Repository
public interface AzEorderTitleRepository extends JpaRepository<AzEorderTitle, String> {

    Optional<AzEorderTitle> findByOrderCode(String orderCode);

    void deleteByOrderCode(String orderCode);

    boolean existsByOrderCode(String orderCode);

    boolean existsByTradeCodeAndOrderCode(String tradeCode, String orderCode);

    void deleteByTradeCodeAndOrderCode(String tradeCode, String orderCode);

    @Query("select a from AzEorderTitle a where a.tradeCode = ?1 and a.isPublished = ?2")
    List<AzEorderTitle> findAllByTradeCodeAndIsPublishedLimit(String tradeCode, Boolean isPublished, Pageable pageable);

    @Modifying
    @Transactional
    @Query("update AzEorderTitle a set a.isPublished = ?1, "
        + " a.gmtModified = ?2, a.modifiedUser = ?3 "
        + " where a.tradeCode = ?4 and a.orderCode = ?5")
	int updateIsPublished(Boolean isPublished, Instant gmtModified, String modifiedUser, String tradeCode, String orderCode);
}
